﻿function openNewTab(e) {
	var idx	= e.index+1;
	var c = Edo.get("tbar_" + idx);
	if(c==null){
	    c = mainTabBar.addChildAt(idx,
			{ id: 'tbar_' + idx, type: 'button', text: navBar.children[e.index].text, arrowMode: 'close', width: '100',
			    onarrowclick: function (e) {
			        //根据idx, 删除对应的容器
			        var c = Edo.get('cont_' + idx);
			        c.destroy();
			        //选中原来Index处					
			        var tabitem = mainTabBar.getChildAt(mainTabBar.selectedIndex);
			        if (!tabitem) {
			            tabitem = mainTabBar.getChildAt(mainTabBar.selectedIndex - 1);
			        }
			        mainTabBar.set('selectedItem', tabitem);
			        navBar.set('selectedIndex', '-1');
			    }
			}
		);
		var module = mainTabContent.addChildAt(idx,
			{
				id:'cont_'+idx,type:"module",width: '100%',height: '100%',style: 'border-top:none'
			}
		);
        module.load('/KSGJ/help.htm');
//			if (idx == 2) {
//			    module.load('/system.htm');
//			}
//			else {
//			    module.load('/KSGJ/help.htm');
//			}
	};
    mainTabBar.set('selectedItem', c);
};

Edo.util.Dom.on(window, 'domload',
function (e) {
    Edo.util.Ajax.request({
        type: 'get',
        url: '/AjaxCommand/getTree.ashx',
        onSuccess: function (text) {
            if (text != "") {
                var data = Edo.util.Json.decode(text);
                navTree.set('data', data);
            }
        }
    });
    Edo.util.Ajax.request({
        type: 'get',
        url: '/AjaxCommand/getSession.ashx',
        onSuccess: function (text) {
            if (text != "") {
                username.set('text', text);
            }
        }
    });
    Edo.build(
    {
        type: 'app', render: document.body, width: '100%', height: '100%', layout: 'vertical',
        children: [
        //顶栏描述
        	{
        	type: 'ct', width: '100%', height: '40', layout: 'horizontal',
        	children: [
	                {
	                    type: 'label', width: '100', height: '100%',
	                    style: 'font-size:20px;padding:5px;padding-top:8px;font-family:微软雅黑, 宋体, Verdana;font-weight:bold;text-align:left; ',
	                    text: '<img src="/ksgj/login.jpg" />'
	                },
                    {
                        type: 'label', width: '100%', height: '100%',
                        style: 'font-size:20px;padding:5px;padding-top:8px;font-family:微软雅黑, 宋体, Verdana;font-weight:bold;text-align:left; ',
                        text: '<a target="_blank" href="http://amos.im.alisoft.com/msg.aw?v=2&uid=%E6%AD%A6%E6%B1%89%E5%8D%93%E5%A4%A9%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&site=cntaobao&s=1&charset=utf-8" ><img border="0" style="vertical-align:middle;" src="http://amos.im.alisoft.com/online.aw?v=2&uid=%E6%AD%A6%E6%B1%89%E5%8D%93%E5%A4%A9%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&site=cntaobao&s=1&charset=utf-8" alt="有问必答" /></a>'
                    },
                    {
                        type: 'label',
                        id: 'username',
                        height: '100%',
                        style: 'line-height:40px'
                    },
	                {
	                    type: 'label',
	                    height: '100%',
	                    style: 'line-height:40px',
	                    text: '<a href="javascript:window.close()" style="color:black;text-decoration:none;">退出</a>'
	                }
                ]
     },
        //工具栏
            {
            id: 'navBar',
            type: 'togglebar',
            layout: 'horizontal',
            cls: 'e-toolbar',
            width: '100%',
            selectedIndex: 0,
            onselectionchange: function (e) {
                if (e.selectedIndex != -1) {
                    openNewTab(e);
                }
            },
            children: [
                    { type: 'button', text: '帮助中心' }
		        ]
        },
        //主界面
            {
            type: 'ct',
            width: '100%',
            height: '100%',
            layout: 'horizontal',
            children: [
            //左侧边
                	{
                	type: 'ct', width: '180', height: '100%',
                	collapseProperty: 'width',
                	enableCollapse: true,
                	splitRegion: 'west',
                	splitPlace: 'after',
                	children: [
		                    {
		                        id: 'leftPanel', type: 'panel', title: '商品类目', width: '100%', height: '100%',
		                        children: [
		                            {
		                                id: 'navTree', type: 'tree', width: '100%', height: '100%', headerVisible: false, autoColumns: true, horizontalLine: false,
		                                columns: [
		                                    {
		                                        header: '类目',
		                                        dataIndex: 'url',
		                                        renderer: function (v, r) {
		                                            //return '<a href="javascript:mainModule.load(\"'+r.url+'\")">'+r.name+'</a>';
		                                            return r.name;
		                                        }
		                                    }
		                                ],
		                                onselectionchange: function (e) {
		                                    var r = this.getSelected();
		                                    if (r && r.url) {
		                                        mainTabBar.set('selectedIndex', 0);
		                                        mainModule.load(r.url);
		                                    }
		                                }
		                            }
		                        ]
		                    }
		                ]
             },
            //右主界面
                	{
                	id: 'mainPanel', type: 'ct', width: '100%', height: '100%', verticalGap: 0,
                	children: [
							{
							    id: 'mainTabBar', type: 'tabbar', selectedIndex: 0, border: [0, 0, 0, 0],
							    onselectionchange: function (e) {
							        mainTabContent.set('selectedIndex', e.index);
							    },
							    children: [
									{ index: 0, type: 'button', text: '主页', width: '100' }
								]
							},
							{
							    id: 'mainTabContent', selectedIndex: 0, layout: 'viewstack', type: 'box', border: [0, 0, 0, 0], width: '100%', height: '100%', verticalScrollPolicy: 'auto',
							    padding: 0, border: 0,
							    onselectionchange: function (e) {
							        alert('content-selected');
							    },
							    children: [
								    { id: 'mainModule', type: "module", width: '100%', height: '100%', style: 'border:1px solid #8BB6EF;border-top:none', src: '/KSGJ/goodlist.htm' }
								]
							}
			  			]
             }//end 右主界面
                ]
        }
        ]
    });
});
